<?php

// seesmic sidebar v0.1 by Steve Purkiss steve@purkiss.com
// with code and help from kosso from podcast.com and douglas karr douglaskarr.com

include 'includes/functions.php';

// start a session  (** VERY important that this goes before *any* output to the browser or the PHP will break **)
session_start();

// look for the session details
if(!$_SESSION['seesmicName']){
// Not authenticated!
    if($_POST[u]!="" && $_POST['p']!=""){
        // look for POST params from the login form
        $suser = ereg_replace("\;\`\\\"\/", "", $_POST['u']);
        $spass = ereg_replace("\;\`\\\"\/", "", $_POST['p']);

        // try to authenticate
        $loggedin = authenticate($suser,$spass);
        if ($loggedin) {
			header("Location: ".$_SERVER['PHP_SELF']);
        } else {
        	echo "<h2 style=\"color:red;\">seesmic login failed</h2>";
        	showLoginForm();
        }
    } else {
        // show the login form
        showLoginForm();
    }
    // important. obviously. :)
    exit;

}

// get user preferences

getUserPreferences();

// get any the passed through variables & session variables

$updatePrefs = false;

// language selection
if ($_GET['lan']) {
	$_SESSION['lan'] = $_GET['lan'];
	$updatePrefs = true;
}

// scroll div height (in pixels)
if ($_GET['sheight']) {
	$_SESSION['sheight'] = $_GET['sheight'];
	$updatePrefs = true;
}

// scroll bar quantity of videos displayed
if ($_GET['squantity']) {
	$_SESSION['squantity'] = $_GET['squantity'];
	$updatePrefs = true;
}

// player size
if ($_GET['player']) {
	$_SESSION['player'] = $_GET['player'];
	$updatePrefs = true;
}

// display Qik videos status
if ($_GET['qikStatus']) {
	$_SESSION['qikStatus'] = $_GET['qikStatus'];
	$updatePrefs = true;
}

if ($updatePrefs) updateUserPreferences();

switch ($_SESSION['player']) {
	case "small" :
		$_SESSION['pwidth'] = "200";
		$_SESSION['pheight'] = "160";
		break;
	case "medium" :
		$_SESSION['pwidth'] = "250";
		$_SESSION['pheight'] = "200";
		break;
	case "large" :
		$_SESSION['pwidth'] = "300";
		$_SESSION['pheight'] = "240";
		break;
	case "xlarge" :
		$_SESSION['pwidth'] = "400";
		$_SESSION['pheight'] = "320";
		break;
}

// display tags status
if (!$_SESSION['tagsStatus']) $_SESSION['tagsStatus'] = "off";

// display the header
displayHeader();

// set up the scroll div
setupScrollDiv();

// display the player div
displayPlayer();

// display the logout/refresh/options/search menu
displayMenu();

?>
<div id='show'></div>
<?php
displayFooter();
?>